package cn.wolfcode.interceptor;


import cn.wolfcode.domain.Employee;
import cn.wolfcode.qo.UserContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LoginInterceptor implements HandlerInterceptor {

    /*编写拦截器*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //先去session获取用户对象 如果为null 就是没有登录过 需要拦截 否则放行
        if (UserContext.getEmployee() == null) {
            response.sendRedirect("/login.html");
            return false;
        }else {
            return true;
        }
    }
}
